<?php

namespace partner\functions\wechat\lib\BankAccountInfo;

use partner\functions\wechat\lib\BaseWechatPartner;
use Exception;

class AccountCertInfo extends BaseWechatPartner
{
    protected $desensitization_properties = [
        'test'
    ];

    protected $upload_properties = [
        'settlement_cert_pic' => 1,
        'relation_cert_pic' => 1,
        'other_cert_pics' => 5
    ];

    public $test = '';

    public function setTest($test)
    {
        $this->test = $test;
        return $this;
    }

    // 结算证明函 可上传1张图片 通过图片上传api获取图片的MediaId 
    // 参考: https://kf.qq.com/faq/220127YjURBN220127fuA7bE.html
    public $settlement_cert_pic = '';

    // 关系证明函 可上传1张图片 通过图片上传api获取图片的MediaId 
    // 参考: https://kf.qq.com/faq/220127YjURBN220127fuA7bE.html
    public $relation_cert_pic = '';

    // 其他补充证明 可上传1-3张图片 通过图片上传api获取图片的MediaId
    public $other_cert_pics = [];


    public function __construct($params = [], $rsa)
    {
        parent::__construct($params, $rsa);
    }

    public function setSettlementCertPic(string $settlement_cert_pic = '')
    {
        if (empty($settlement_cert_pic))
            throw new Exception("结算证明函不能为空");
        if (! file_exists($settlement_cert_pic))
            throw new Exception("{$settlement_cert_pic}不存在");

        $this->settlement_cert_pic = $settlement_cert_pic;
        return $this;
    }

    public function setRelationCertPic(string $relation_cert_pic = '')
    {
        if (empty($relation_cert_pic))
            throw new Exception("关系证明函不能为空");
        if (! file_exists($relation_cert_pic))
            throw new Exception("{$relation_cert_pic}不存在");

        $this->relation_cert_pic = $relation_cert_pic;
        return $this;
    }

    public function setOtherCertPics(array $other_cert_pics = [])
    {
        if ($other_cert_pics) {
            foreach ($other_cert_pics as $other_cert_pic) {
                if (empty($other_cert_pic))
                    continue;
                if (! file_exists($other_cert_pic))
                    throw new Exception("{$other_cert_pic}不存在");

                array_push($this->other_cert_pics, $other_cert_pic);
            }
        }
        return $this;
    }
}
